﻿using System;
using PasteLoggerBoard.usermodels;

namespace PasteLoggerBoard
{
    /// <summary>
    /// 
    /// </summary>
    public class PasteLoggerBoardException : Exception
    {
        /// <summary>
        /// 
        /// </summary>
        public int Code { get; set; } = 500;

        /// <summary>
        /// 
        /// </summary>
        /// <param name="message"></param>
        /// <param name="code"></param>
        public PasteLoggerBoardException(string message, ExceptionCode code = ExceptionCode.ShowInfo) : base(message)
        {
            Code = (int)code;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="message"></param>
        /// <param name="code"></param>
        public PasteLoggerBoardException(string message, string code) : base(message)
        {
            int.TryParse(code, out var _code);
            Code = _code;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="message"></param>
        /// <param name="code"></param>
        public PasteLoggerBoardException(string message, int code) : base(message)
        {
            //int.TryParse(code, out var _code);
            Code = code;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="message"></param>
        /// <param name="innerException"></param>
        public PasteLoggerBoardException(string message, Exception innerException) : base(message, innerException)
        {

        }

    }
    /// <summary>
    /// 异常分类
    /// </summary>
    public enum ExceptionCode
    {
        /// <summary>
        /// 提示性错误
        /// </summary>
        ShowInfo = 700,
        /// <summary>
        /// 输入错误
        /// </summary>
        ModelErr = 400,
        /// <summary>
        /// 未登录或者密钥错误
        /// </summary>
        UnAuth = 401,
        /// <summary>
        /// 没有权限
        /// </summary>
        UnRole = 403
    }

    /// <summary>
    /// 
    /// </summary>
    public class InputSearchBase
    {
        /// <summary>
        /// 页码
        /// </summary>
        public int page { get; set; } = 1;

        /// <summary>
        /// 页大小
        /// </summary>
        public int size { get; set; } = 20;

        /// <summary>
        /// 
        /// </summary>
        public string word { get; set; } = "";
    }

    /// <summary>
    /// 查找用户条件
    /// </summary>
    public class InputSearchUser
    {
        /// <summary>
        /// 页码
        /// </summary>
        public int page { get; set; } = 1;

        /// <summary>
        /// 页大小
        /// </summary>
        public int size { get; set; } = 20;

        /// <summary>
        /// 部门ID 组别ID
        /// </summary>
        public int partid { get; set; } = 0;
        /// <summary>
        /// 角色名称
        /// </summary>
        public string grade { get; set; } = "";
        /// <summary>
        /// 哪一个项目的
        /// </summary>
        public int projectid { get; set; }

        /// <summary>
        /// 哪一个任务的，可能projectid没法提供！
        /// </summary>
        public int orderid { get; set; }
    }

    /// <summary>
    /// 查询用户列表，是否绑定某一个对象
    /// </summary>
    public class InputUserBind
    {
        /// <summary>
        /// 一级条件
        /// </summary>
        public int projectid { get; set; }

        /// <summary>
        /// 二级条件 一级条件为0表示二级条件为绑定对象条件
        /// </summary>
        public int partid { get; set; }

        /// <summary>
        /// 关键字搜索
        /// </summary>
        public string word { get; set; }
    }

    /// <summary>
    /// 报表请求条件
    /// </summary>
    public class InputSearchReport
    {
        /// <summary>
        /// 开始时间
        /// </summary>
        public DateTime? datestart { get; set; } = null;

        /// <summary>
        /// 结束时间
        /// </summary>
        public DateTime? dateend { get; set; } = null;

        /// <summary>
        /// 某一个用户的
        /// </summary>
        public int userid { get; set; } = 0;

        /// <summary>
        /// 某一个项目的
        /// </summary>
        public int projectid { get; set; } = 0;
    }

    /// <summary>
    /// 
    /// </summary>
    public class HistoryDate
    {

        /// <summary>
        ///  yyyyMMdd
        /// </summary>
        public int Daily { get; set; }

        /// <summary>
        /// 
        /// </summary>
        public int Hour { get; set; }

        /// <summary>
        /// 
        /// </summary>
        public string AppName { get; set; }

        /// <summary>
        /// 
        /// </summary>
        public string Level { get; set; }

        /// <summary>
        /// 访问量
        /// </summary>
        public int Total { get; set; }
    }


    /// <summary>
    /// 日志模型
    /// </summary>
    public class LoggerModel
    {
        /// <summary>
        /// 日志发生时间
        /// </summary>
        public string Timestamp { get; set; }
        /// <summary>
        /// 日志层级
        /// </summary>
        public string Level { get; set; }
        /// <summary>
        /// 消息模板
        /// </summary>
        public string MessageTemplate { get; set; }
        /// <summary>
        /// 日志的属性
        /// </summary>
        public PropertiesModel Properties { get; set; }

        /// <summary>
        /// 
        /// </summary>
        public string Exception { get; set; }
    }
    /// <summary>
    /// 日志的属性
    /// </summary>
    public class PropertiesModel
    {
        /// <summary>
        /// 哪一个应用触发的
        /// </summary>
        public string AppName { get; set; }

        /// <summary>
        /// 访问状态
        /// </summary>
        public int StatusCode { get; set; }

        /// <summary>
        /// 耗时 毫秒
        /// </summary>
        public double ElapsedMilliseconds { get; set; }

        /// <summary>
        /// 访问路径 128
        /// </summary>
        public string Path { get; set; }

        /// <summary>
        /// 
        /// </summary>
        public string QueryString { get; set; }

        /// <summary>
        ///  128
        /// </summary>
        public string Host { get; set; }

        /// <summary>
        /// 
        /// </summary>
        public string PathBase { get; set; }

        /// <summary>
        /// 
        /// </summary>
        public string ConnectionId { get; set; }

        /// <summary>
        /// 128
        /// </summary>
        public string RequestId { get; set; }

        /// <summary>
        /// 
        /// </summary>
        public string UserAgent { get; set; }

        /// <summary>
        /// 
        /// </summary>
        public string ClientIP { get; set; }

    }

    /// <summary>
    /// 
    /// </summary>
    public class RabbitConfig
    {
        /// <summary>
        /// 地址
        /// </summary>
        public string HostName { get; set; }

        /// <summary>
        /// 端口
        /// </summary>
        public int Port { get; set; }

        /// <summary>
        /// 作用域
        /// </summary>
        public string VirtualHost { get; set; } = "/";

        /// <summary>
        /// 账号
        /// </summary>
        public string UserName { get; set; }

        /// <summary>
        /// 密码
        /// </summary>
        public string Password { get; set; }

        /// <summary>
        /// 交换机名称
        /// </summary>
        public string Exchange { get; set; }

        /// <summary>
        /// 交换机类型 direct直连模式 topic统配模式
        /// </summary>
        public string ExchangeType { get; set; }

        /// <summary>
        /// 队列名称
        /// </summary>
        public string QueueName { get; set; }

        /// <summary>
        /// true:Durable(持久化) false:Transient(瞬时模式)
        /// </summary>
        public bool Durable { get; set; } = true;

        /// <summary>
        /// 分配规则 msg.* msg.# 
        /// *:匹配一个单词
        /// #:匹配多个单词，单词之间用.隔开
        /// 匹配模式的时候exchangetype需要为topic
        /// </summary>
        public string RouteKey { get; set; }

        /// <summary>
        /// 分配规则 msg.* msg.# 
        /// *:匹配一个单词
        /// #:匹配多个单词，单词之间用.隔开
        /// 匹配模式的时候exchangetype需要为topic
        /// </summary>
        public string WatchKey { get; set; }

        /// <summary>
        /// 客户端名称
        /// </summary>
        public string ClientName { get; set; }

        /// <summary>
        /// 配送模式 1不持续模式 2持续模式
        /// </summary>
        public int DeliveryMode { get; set; } = 2;

        /// <summary>
        /// 是否启用后台线程处理IO
        /// </summary>
        public bool UseBackgroundThreadsForIO { get; set; } = true;

        /// <summary>
        /// 写入通道数量
        /// </summary>
        public int MaxChannelCount { get; set; } = 2;
    }

}
